<template>
  <div class="evaluete-info">
    <div class="header-info">
      <div class="header-title">用户评价</div>
      <div class="header-more">更多</div>
    </div>
    <div class="content-info" v-if="Object.keys(evalueteInfo).length !== 0">
      <div>
        <div class="user">
          <span>
            <img :src="evaluete.user.avatar" alt />
          </span>
          <span class="name">{{evaluete.user.uname}}</span>
        </div>
        <div class="evaluete-detail">
          <div class="desc">{{evaluete.content}}</div>
          <div class="other">
            <span class="date">{{evaluete.created | formatDate('yyyy-MM-dd')}}</span>
            <span class="color">{{evaluete.style}}</span>
          </div>
          <div class="evaluete-img" v-if="evaluete.images && evaluete.images.length">
            <img v-for="(item, index) in evaluete.images" :key="index" :src="item" alt />
          </div>
        </div>
      </div>
    </div>
    <div v-else>暂时没有评论</div>
  </div>
</template>

<script>
export default {
  props: {
    evalueteInfo: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  computed: {
    evaluete() {
      return this.evalueteInfo.list[0]
    },
  },
  filters: {
    // 处理时间戳
    formatDate(date, format) {
      if (typeof date == 'string') {
        return date
      }
      if (!format) format = 'yyyy-MM-dd hh:mm:ss'
      if (!date || date == null) return null
      // * 1000转为毫秒
      date = new Date(date * 1000)
      let o = {
        'M+': date.getMonth() + 1, // 月份
        'd+': date.getDate(), // 日
        'h+': date.getHours(), // 小时
        'm+': date.getMinutes(), // 分
        's+': date.getSeconds(), // 秒
        'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
        S: date.getMilliseconds(), // 毫秒
      }
      // 获取年份
      if (/(y+)/.test(format))
        format = format.replace(
          RegExp.$1,
          (date.getFullYear() + '').substr(4 - RegExp.$1.length)
        )
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(format))
          format = format.replace(
            RegExp.$1,
            RegExp.$1.length === 1
              ? o[k]
              : ('00' + o[k]).substr(('' + o[k]).length)
          )
      }
      return format
    },
  },
}
</script>

<style scoped>
.evaluete-info {
  padding: 8px 8px 10px;
  border-bottom: solid 4px rgba(100, 100, 100, 0.1);
}
.header-info {
  padding: 10px 0;
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid rgba(100, 100, 100, 0.1);
}
.content-info {
  margin-top: 8px;
}
.content-info .user img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
.content-info .user .name {
  position: relative;
  top: -15px;
  left: 8px;
}
.evaluete-detail .desc {
  padding: 4px;
  text-indent: 2em;
  color: var(--color-text);
}
.evaluete-detail .other {
  color: var(--color-text);
}
.evaluete-detail .other span {
  padding: 4px;
}
.evaluete-detail .evaluete-img {
  display: flex;
}
.evaluete-img img {
  width: 70px;
  height: 70px;
  vertical-align: middle;
  padding-right: 6px;
}
</style>